package com.ruoyi.shop.service.impl;

import java.util.List;

import com.ruoyi.shop.api.RemoteImageService;
import com.ruoyi.shop.api.RemoteOilService;
import com.ruoyi.shop.api.domain.ChePetrol;
import com.ruoyi.shop.api.domain.ChePetrolOil;
import com.ruoyi.shop.api.domain.PetrolImage;
import com.ruoyi.shop.mapper.ChePetrolOilMapper;
import com.ruoyi.shop.mapper.PetrolImageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.shop.mapper.ChePetrolMapper;
import com.ruoyi.shop.service.IChePetrolService;

/**
 * 加油站Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-02
 */
@Service
public class ChePetrolServiceImpl implements IChePetrolService 
{
    @Autowired
    private ChePetrolMapper chePetrolMapper;
    @Autowired
    private PetrolImageMapper petrolImageMapper;

    @Autowired
    private RemoteOilService remoteOilService;

    @Autowired
    private RemoteImageService remoteImageService;

    @Autowired
    private ChePetrolOilMapper chePetrolOilMapper;

    /**
     * 查询加油站
     * 
     * @param id 加油站主键
     * @return 加油站
     */
    @Override
    public ChePetrol selectChePetrolById(Long id)
    {
        ChePetrol chePetrol = chePetrolMapper.selectChePetrolById(id);
        List<ChePetrolOil> chePetrolOils = chePetrolOilMapper.selectChePetrolOilListById(id);
        chePetrol.setChePetrolOil(chePetrolOils);
        PetrolImage petrolImage = petrolImageMapper.selectPetrolImageByPetrolId(id);
        chePetrol.setPetrolImage(petrolImage);
        return chePetrol;
    }

    /**
     * 查询加油站列表
     * 
     * @param chePetrol 加油站
     * @return 加油站
     */
    @Override
    public List<ChePetrol> selectChePetrolList(ChePetrol chePetrol)
    {
        List<ChePetrol> chePetrols = chePetrolMapper.selectChePetrolList(chePetrol);
        for (ChePetrol petrol : chePetrols) {
            List<ChePetrolOil> chePetrolOils = remoteOilService.selectOilListById(petrol.getId(),null);
            petrol.setChePetrolOil(chePetrolOils);
            PetrolImage petrolImage = petrolImageMapper.selectPetrolImageByPetrolId(petrol.getId());
            petrol.setPetrolImage(petrolImage);
        }
        return chePetrols;
    }


    /**
     * 新增加油站
     * 
     * @param chePetrol 加油站
     * @return 结果
     */
    @Override
    public int insertChePetrol(ChePetrol chePetrol)
    {
        return chePetrolMapper.insertChePetrol(chePetrol);
    }

    /**
     * 修改加油站
     * 
     * @param chePetrol 加油站
     * @return 结果
     */
    @Override
    public int updateChePetrol(ChePetrol chePetrol)
    {
        return chePetrolMapper.updateChePetrol(chePetrol);
    }

    /**
     * 批量删除加油站
     * 
     * @param ids 需要删除的加油站主键
     * @return 结果
     */
    @Override
    public int deleteChePetrolByIds(Long[] ids)
    {
        return chePetrolMapper.deleteChePetrolByIds(ids);
    }

    /**
     * 删除加油站信息
     * 
     * @param id 加油站主键
     * @return 结果
     */
    @Override
    public int deleteChePetrolById(Long id)
    {
        return chePetrolMapper.deleteChePetrolById(id);
    }
}
